package increasingBST

// Definition for a binary tree node.
type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func increasingBST(root *TreeNode) *TreeNode {
	var left *TreeNode = root
	if root.Left == nil && root.Right == nil {
		return root
	}
	if root.Left != nil {
		left = increasingBST(root.Left)
		taill := left
		root.Left = nil
		for {
			if taill.Right == nil {
				taill.Right = root
				break
			}
			taill = taill.Right
		}
	}
	if root.Right != nil {
		right := increasingBST(root.Right)
		root.Right = right
	}
	return left
}

// func MidSearch(root *TreeNode) {
// 	if root == nil {
// 		fmt.Println(root.Val)
// 	}

// 	MidSearch(root.Left)
// 	fmt.Println(root.Val)
// 	MidSearch(root.Right)

// }
